package transactionimplementation

import (
	Model "SoftwareEngineering/Model"
	"SoftwareEngineering/TransactionApplication"
	"time"
	DataBase "SoftwareEngineering/DataBase"
)


type PaydayTransaction struct {
	itsPayDate  time.Time
	itsPayCheck map[int]Model.Paycheck
}

func (p *PaydayTransaction) Execute() {
	ids := DataBase.PayrollDatabase.GetAllEmployee()

	for _, id := range ids {
		e := DataBase.PayrollDatabase.GetEmployee(id)

		if e != nil {
			if e.IsPayDate(p.itsPayDate) {
				pc := Model.NewPaycheck(e.GetPayPeriodStartDate(p.itsPayDate), p.itsPayDate)
				p.itsPayCheck[id] = pc
				e.Payday(pc)
			}
		}
	}
}

func (p *PaydayTransaction) GetPaycheck(empid int) Model.Paycheck {
	if pc, ok := p.itsPayCheck[empid]; ok {
		return pc
	}

	return Model.Paycheck{}
}

func (p *PaydayTransaction) GetPaycheckCount() int {
	return len(p.itsPayCheck)
}
